package com.xxx.springboot.handler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.xxx.springboot.pojo.entity.User;
import com.xxx.springboot.pojo.vo.UserImportVO;
import com.xxx.springboot.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 3. easy poi excel校验器
 * @author guwq
 * @since 2021/6/26
 */
@Slf4j
@Component
public class UserVerifyHandler implements IExcelVerifyHandler<UserImportVO> {

    @Autowired
    private UserService userService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(UserImportVO userImportVO) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();
        // 校验用户名是否存在
        User user = userService.getByName(userImportVO.getName());
        if(user==null){
            result.setMsg("姓名不存在");
            result.setSuccess(false);
        } else {
            result.setSuccess(true);
        }
        return result;
    }
}
